package com.tanhua.server.controller;

import com.tanhua.model.mongo.UserLike;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.MovementService;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;
    @Autowired
    private MovementService movementService;


    /**
     * 查询通用设置
     */
    @GetMapping("/settings")
    public ResponseEntity settings() {
        SettingsVo vo = settingsService.settings();
        return ResponseEntity.ok(vo);
    }

    /**
     * 设置陌生人问题
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map) {
        //获取参数
        String content = (String) map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok(null);
    }

    /**
     * 通知设置
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map) {
        //获取参数
        settingsService.saveSettings(map);
        return ResponseEntity.ok(null);
    }

    /**
     * 分页查询黑名单列表
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        //1、调用service查询
        PageResult pr = settingsService.blacklist(page,size);
        //2、构造返回
        return ResponseEntity.ok(pr);
    }

    /**
     * 取消黑名单
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long blackUserId) {
        settingsService.deleteBlackList(blackUserId);
        return ResponseEntity.ok(null);
    }

    //互相喜欢，喜欢，粉丝 - 统计
    @GetMapping("/counts")
    public ResponseEntity counts() {
        Map map = settingsService.counts();
        return ResponseEntity.ok(map);
    }

    //喜欢 - 取消
    @DeleteMapping("/like/{uid}")
    public ResponseEntity notLikeUser(@PathVariable("uid") Long likeUserId) {//我喜欢的用户id
        settingsService.notLikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    //粉丝 - 喜欢
    @PostMapping("/fans/{uid}")
    public ResponseEntity fans(@PathVariable("uid") Long likeUserId) {//喜欢我的用户id
        settingsService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    //互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表
    @GetMapping("/friends/{type}")
    public ResponseEntity friends(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pagesize,
                                  String nickname,
                                  @PathVariable("type")Long type) {
        PageResult pr = settingsService.findFriends(page, pagesize,nickname, type);
        return ResponseEntity.ok(pr);
    }

    //是否喜欢（新增接口）
    @GetMapping("/{uid}/alreadyLove")
    public ResponseEntity alreadyLove(@PathVariable("uid") Long likeUserId){
        Boolean aboolean = settingsService.alreadyLove(likeUserId);
        return ResponseEntity.ok(aboolean);
    }

}